﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teigha.DatabaseServices;
using SRB.Tg.Model;
using Teigha.Runtime;
using SRB.Tg.DrawingStandard;
using SRB.Tg.Cad_Bll;
using Teigha.Export_Import;
using System.Drawing;
using Teigha.Geometry;
using Teigha.GraphicsSystem;
using SRB.Tg.Cad_Bll;
using System.Collections.Specialized;
using System.IO;
using SRB.Tg.Operate;
using SRB.Tg.Common;
using SRB.Tg.Operate.Operate;
using System.Data;

namespace ExportSteelTrussBeam
{
    public class ExportSteelTrussBeamStructure
    {
        static string appPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "CADFiles";
        static System.Data.DataTable dtProject;
        static System.Data.DataTable dtProjectConfig;

        /// <summary>
        /// 钢桁梁节点构造图
        /// </summary>
        /// <param name="bridgeId"></param>
        /// <param name="catalogid"></param>
        /// <param name="_appPath"></param>
        /// <returns></returns>
        public static string DrawingSteelTrussBeamStructure(string bridgeId, string catalogid, string _appPath = "")
        {
            string filePath = "";
            DrawingSteelTrussStructure P1 = new DrawingSteelTrussStructure(bridgeId, "0", out dtProject);
            string sqlMainId = "select * from busi_bridge where id='" + bridgeId + "' ";
            string mainId = MySqlHelper.ExecuteDataTable(sqlMainId, CommandType.Text).Rows[0]["main_id"].ToString();
            string sqlBridge = "select * from vi_bridge where  id='" + mainId + "'";
            System.Data.DataTable dtAviationBridgeInfo = MySqlHelper.ExecuteDataTable(sqlBridge, CommandType.Text);
            List<Tuple<double, double, double>> tupleLst = new List<Tuple<double, double, double>>();
            List<Tuple<double, double, double>> tupleWLst = new List<Tuple<double, double, double>>();
            List<Tuple<double, bool>> tupDimleLst = new List<Tuple<double, bool>>();
            List<Tuple<string, double, double, DataRow, bool>> tupGLLst = new List<Tuple<string, double, double, DataRow, bool>>();
            List<Tuple<string, double, double, DataRow, bool, double>> tupAddGLLst = new List<Tuple<string, double, double, DataRow, bool, double>>();
            List<Tuple<string, double>> tupleGLLst = new List<Tuple<string, double>>();
            List<Tuple<string, double>> tupleGLLstAll = new List<Tuple<string, double>>();
            List<Tuple<string, double>> tupleGLLstLightAll = new List<Tuple<string, double>>();
            Dictionary<Tuple<string, double, double, DataRow, bool>, int> dicGL = new Dictionary<Tuple<string, double, double, DataRow, bool>, int>();
            Dictionary<Tuple<string, double, double, DataRow, bool, double>, int> dicAddGL = new Dictionary<Tuple<string, double, double, DataRow, bool, double>, int>();
            double bridgeW = 4000, bridgeSlope = 0.025, divHeight = 3000;
            bool isDL = false;
            if (dtAviationBridgeInfo.Rows.Count > 0)
            {
                //主梁布跨信息
                string sqlSection = "select * from vi_aviation_section where  bridge_id='" + bridgeId + "' ";
                if(bridgeId== "1802595897232498690")
                    isDL = true;
                System.Data.DataTable dtSection = MySqlHelper.ExecuteDataTable(sqlSection, CommandType.Text);
                double startStation = double.Parse(dtAviationBridgeInfo.Rows[0]["start_station"].ToString()) * 100;
                bridgeSlope = double.Parse(dtAviationBridgeInfo.Rows[0]["bridge_slope"].ToString()) * 0.01;
                double bridgeLength = double.Parse(dtAviationBridgeInfo.Rows[0]["bridge_length"].ToString()) * 100;
                //int num = (int)(bridgeLength / divCap);
                //num = (bridgeLength- divCap*num)>0 ? num : num + 1 ;
                string sqlSpan = "select * from vi_aviation_bridge where  bridge_id='" + dtAviationBridgeInfo.Rows[0]["bridge_id"].ToString() + "' order by station asc";
                System.Data.DataTable dtAviationBridge = MySqlHelper.ExecuteDataTable(sqlSpan, CommandType.Text);
                double divCap = double.Parse(dtAviationBridgeInfo.Rows[0]["beam_section_width"].ToString()) * 1000;
                divHeight = double.Parse(dtAviationBridgeInfo.Rows[0]["beam_height"].ToString()) * 1000;

                double light_width=string.IsNullOrWhiteSpace(dtAviationBridgeInfo.Rows[0]["light_width"].ToString())?4500 : double.Parse(dtAviationBridgeInfo.Rows[0]["light_width"].ToString()) * 1000;
                double light_length = string.IsNullOrWhiteSpace(dtAviationBridgeInfo.Rows[0]["light_length"].ToString()) ? divCap : double.Parse(dtAviationBridgeInfo.Rows[0]["light_length"].ToString()) * 1000;
                double light_left_length = string.IsNullOrWhiteSpace(dtAviationBridgeInfo.Rows[0]["light_left_length"].ToString()) ? 0 : double.Parse(dtAviationBridgeInfo.Rows[0]["light_left_length"].ToString()) * 1000;
                double light_right_length = string.IsNullOrWhiteSpace(dtAviationBridgeInfo.Rows[0]["light_right_length"].ToString()) ? 0 : double.Parse(dtAviationBridgeInfo.Rows[0]["light_right_length"].ToString()) * 1000;


                double light_start_station = double.Parse(dtAviationBridgeInfo.Rows[0]["light_start_station"].ToString()) * 100;
                double light_distinct = double.Parse(dtAviationBridgeInfo.Rows[0]["light_distinct"].ToString()) * 1000;
                double startL = light_start_station - startStation;
                double lenLight = startL * 10;

                int numCap = 3;
                numCap = (int)(10 * 1000 / divCap)>3?(int)(10 * 1000 / divCap):3;
                int num = (int)(bridgeLength * 10 / divCap);
              
                double divCapLast = bridgeLength * 10 - num * divCap;
                num = (bridgeLength * 10 - divCap * num) > 0 ? num + 1 : num;
                if (dtSection.Rows.Count > 0)
                {
                    #region 数据处理,变高变宽待处理
                    //divCap = double.Parse(dtSection.Rows[0]["segment_length"].ToString()) * 1000;
                    //divHeight = double.Parse(dtSection.Rows[0]["segment_length"].ToString()) * 1000;

                    //List<double> spanLLst = new List<double>();
                    #region 数据准备
                    DataRow dr = dtSection.Rows[0];
                    string straight_web_bar = dr["straight_web_bar"].ToString().Contains("HN") ? dr["straight_web_bar"].ToString() : "矩形管" + dr["straight_web_bar"].ToString();
                    string reinforced_straight_web_bar = dr["reinforced_straight_web_bar"].ToString().Contains("HN") ? dr["reinforced_straight_web_bar"].ToString() : "矩形管" + dr["reinforced_straight_web_bar"].ToString();
                    string diagonal_brace = dr["diagonal_brace"].ToString().Contains("HN") ? dr["diagonal_brace"].ToString() : "矩形管" + dr["diagonal_brace"].ToString();
                    string reinforced_diagonal_brace = dr["reinforced_diagonal_brace"].ToString().Contains("HN") ? dr["reinforced_diagonal_brace"].ToString() : "矩形管" + dr["reinforced_diagonal_brace"].ToString();

                    string[] spanL = { "500" };
                    string[] spanLRe = { "500" };
                    string[] spanW = { "500" };


                    if (dtSection.Rows.Count > 0)
                    {
                        string span = dtSection.Rows[0]["span_height_segment"].ToString();
                        spanL = span.Split('+');

                        string spanRe = dtSection.Rows[0]["reinforced_length_segment"].ToString();
                        spanLRe = spanRe.Split('+');

                        string spanWS = dtSection.Rows[0]["span_width_segment"].ToString();
                        spanW = spanWS.Split('+');
                    }

                    for (int j = 0; j < spanL.Length; j++)
                    {

                        string[] sp = spanL[j].Split('*');
                        double lenSpan = double.Parse(sp[0]);

                        double ht = 3;
                        if (sp[1].Contains("-"))
                        {
                            string[] heightLst = sp[1].Replace("(", "").Replace(")", "").Replace("（", "").Replace("）", "").Split('-');
                            double h1 = double.Parse(heightLst[0]);
                            double h2 = double.Parse(heightLst[1]);
                            Tuple<double, double, double> tu = new Tuple<double, double, double>(lenSpan, h1, h2);
                            tupleLst.Add(tu);
                        }
                        else
                        {
                            ht = double.Parse(sp[1]);
                            Tuple<double, double, double> tu = new Tuple<double, double, double>(lenSpan, ht, ht);
                            tupleLst.Add(tu);
                        }

                    }

                    for (int j = 0; j < spanLRe.Length; j++)
                    {
                        double lenSeg = double.Parse(spanLRe[j].Replace("(", "").Replace(")", "").Replace("（", "").Replace("）", ""));
                        if (spanLRe[j].Contains("(") || spanLRe[j].Contains("（"))
                        {
                            Tuple<double, bool> tu = new Tuple<double, bool>(lenSeg, true);
                            tupDimleLst.Add(tu);
                        }
                        else
                        {
                            Tuple<double, bool> tu = new Tuple<double, bool>(lenSeg, false);
                            tupDimleLst.Add(tu);
                        }

                    }

                    for (int j = 0; j < spanW.Length; j++)
                    {
                        string[] sp = spanW[j].Split('*');
                        double lenSpan = double.Parse(sp[0]);

                        double wt = 3;
                        if (sp[1].Contains("-"))
                        {
                            string[] widthLst = sp[1].Replace("(", "").Replace(")", "").Replace("（", "").Replace("）", "").Split('-');
                            double w1 = double.Parse(widthLst[0]);
                            double w2 = double.Parse(widthLst[1]);
                            Tuple<double, double, double> tu = new Tuple<double, double, double>(lenSpan, w1, w2);
                            tupleWLst.Add(tu);
                        }
                        else
                        {
                            wt = double.Parse(sp[1]);
                            Tuple<double, double, double> tu = new Tuple<double, double, double>(lenSpan, wt, wt);
                            tupleWLst.Add(tu);
                        }
                    }
                    #endregion

                    double leSeg = 0;

                    string steel_tower_type0 = dtAviationBridge.Rows[1]["steel_tower_type"].ToString();


                    int no = 0;
                    int numGL = 5;
                    double len1 = 0, len2 = 0;
                    double bw = 4000;
                    string gl1 = "GL1";
                    string gl2 = "GL2";
                    string gl6 = "GL6";
                    string gl5 = "GL5";

                    int firstIndex = tupDimleLst.FindIndex(o => o.Item2 == true);
                    int lastIndex = tupDimleLst.FindLastIndex(o => o.Item2 == true);
                    //string reinforced_straight_web_bar = dtSection.Rows[0]["reinforced_straight_web_bar"].ToString();
                    string reinforced_straight_web_bar_add = dtSection.Rows[0]["reinforced_straight_web_bar_add"].ToString();
                    bool isReAdd = false;
                    if (reinforced_straight_web_bar != reinforced_straight_web_bar_add)
                    {
                        isReAdd = true;
                    }
                    for (int j = 0; j < tupDimleLst.Count; j++)
                    {
                        leSeg += tupDimleLst[j].Item1 * 1000;

                        double lenCal = tupDimleLst[j].Item1 * 1000;
                        double lenAddCal = tupDimleLst[j].Item1 * 1000;
                        int numGL2 = 0;
                        double mid = 0;
                        if (!tupDimleLst[j].Item2)
                        {
                            if (j == 0 || j == tupDimleLst.Count - 1)
                            {
                                if (j == tupDimleLst.Count - 1)
                                {
                                    if (leSeg < bridgeLength*10)
                                        lenCal = tupDimleLst[j].Item1 * 1000 - 0.5 * divCap + divCapLast;
                                    else
                                        lenCal = tupDimleLst[j].Item1 * 1000 - 0.5 * divCap;
                                }
                                else
                                    lenCal = tupDimleLst[j].Item1 * 1000 - 0.5 * divCap;
                                //lenCal = tupDimleLst[j].Item1 * 1000 - 0.5 * divCap;
                            }
                            else
                            {
                                lenCal = tupDimleLst[j].Item1 * 1000 - divCap;
                               
                            }

                        }
                        else
                        {
                            lenAddCal = tupDimleLst[j].Item1 * 1000 + divCap;
                            numGL2 = (int)((lenAddCal) / (divCap * numCap)) / 2;
                            mid = lenAddCal - numGL2 * 2 * divCap * numCap;
                            numGL2 = numGL2 * 2;
                            if (mid <= divCap)
                            {
                                mid = lenAddCal - (numGL2) * divCap * numCap + 2 * divCap;
                            }
                        }
                        int numGL1 = (int)(lenCal / (divCap * numCap));
                        if (lenCal - numGL1 * divCap * numCap <= divCap && (lenCal - numGL1 * divCap * numCap > 0))
                            numGL1 = numGL1 - 1;
                        double last = lenCal - numGL1 * divCap * numCap;
                        //int numGL2 = (int)(lenAddCal / (divCap * numCap));
                        //double mid = lenAddCal - numGL2 * divCap * numCap;
                        int no1 = (int)(last / divCap);
                        int no2 = (int)(mid / divCap);
                        bw = divCap;

                        bool isUp = false;

                        for (int m = no; m <= num; m++)
                        {
                            if(no==34)
                            {

                            }
                            if (m < numCap)
                            {
                                //if ((m + 1) % 2 == 0)
                                //    isUp = false;
                                //else
                                //    isUp = true;
                            }
                            else
                            {
                                if ((m - numCap) % 2 == 0)
                                    isUp = true;
                                else
                                    isUp = false;
                            }
                            #region 数据处理
                            try
                            {
                                double leSegW = 0;
                                bw = tupleWLst[0].Item2 * 1000;
                                for (int n = 0; n < tupleWLst.Count; n++)
                                {
                                    leSegW += tupleWLst[n].Item1 * 1000;
                                    double len = m * divCap;
                                    if (len < leSegW)
                                    {

                                        if (j > 0)
                                            bw = tupleWLst[n].Item2 * 1000 + ((len - tupleWLst[n - 1].Item1 * 1000) / tupleWLst[n].Item1 * 1000) * (tupleWLst[n].Item3 * 1000 - tupleWLst[n].Item2 * 1000);
                                        else
                                            bw = tupleWLst[n].Item2 * 1000 + (len / tupleWLst[n].Item1 * 1000) * (tupleWLst[n].Item3 * 1000 - tupleWLst[n].Item2 * 1000);
                                        break;
                                    }
                                }
                            }
                            catch { }
                            finally
                            {
                                bridgeW = bw;
                            }

                            bw = divHeight;
                            try
                            {
                                double leSegH = 0;
                                divHeight = tupleLst[0].Item2 * 1000;
                                for (int n = 0; n < tupleLst.Count; n++)
                                {
                                    leSegH += tupleLst[n].Item1 * 1000;
                                    double len = m * divCap;
                                    if (len < leSegH)
                                    {

                                        if (j > 0)
                                            bw = tupleLst[n].Item2 * 1000 + ((len - tupleLst[n - 1].Item1 * 1000) / tupleLst[n].Item1 * 1000) * (tupleLst[n].Item3 * 1000 - tupleLst[n].Item2 * 1000);
                                        else
                                            bw = tupleLst[n].Item2 * 1000 + (len / tupleLst[n].Item1 * 1000) * (tupleLst[n].Item3 * 1000 - tupleLst[n].Item2 * 1000);
                                        break;
                                    }
                                }
                            }
                            catch { }
                            finally
                            {
                                divHeight = bw;
                            }
                            #endregion

                            if (steel_tower_type0 == "2")
                            {
                                #region Y
                                if (m <= no1)
                                {
                                    if (m == no1)
                                    {
                                        if (numCap == 3)
                                        {
                                            gl1 = "GL1a";
                                        }
                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>("GL4", last, divHeight, dtSection.Rows[0], isUp));
                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>("GL4", last, divHeight, dtSection.Rows[0], isUp), 1);
                                        len1 = (m + 0.5) * divCap;
                                        no = m + 1;
                                    }
                                }
                                else
                                {
                                  
                                    if ((m + 0.5) * divCap <= leSeg && !tupDimleLst[j].Item2)
                                    {
                                        #region 非墩顶区
                                        if (j == 0)
                                        {
                                            if ((m - no) % numCap == numCap - 1)
                                            {
                                                if (numCap == 3)
                                                {
                                                    if (gl1 == "GL1")
                                                    {
                                                        gl1 = "GL1a";
                                                        gl2 = "GL2a";
                                                    }
                                                    else
                                                    {
                                                        gl1 = "GL1";
                                                        gl2 = "GL2";
                                                    }
                                                }
                                                if (j == firstIndex - 1 && (m + 0.5 - numCap) * divCap <= leSeg && (m + 0.5 + numCap) * divCap >= leSeg && isDL)
                                                {
                                                    if (!tupGLLst.Exists(o => o.Item1 == "GL1b"))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>("GL1b", numCap * divCap, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>("GL1b", numCap * divCap, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == "GL1b");
                                                        dicGL[tu] += 1;
                                                    }
                                                }
                                                else
                                                {
                                                    if (!tupGLLst.Exists(o => o.Item1 == gl1))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>(gl1, numCap * divCap, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>(gl1, numCap * divCap, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == gl1);
                                                        dicGL[tu] += 1;
                                                    }
                                                }

                                                len1 = (m + 0.5) * divCap;
                                                no = m + 1;
                                            }
                                            if (((m + 1) * divCap >= leSeg))
                                            {
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            #region 特殊处理
                                            if ((m - no) % numCap == numCap - 1 && (m + no1) * divCap < leSeg)
                                            {
                                                if (numCap == 3)
                                                {
                                                    if (gl1 == "GL1")
                                                    {
                                                        gl1 = "GL1a";
                                                        gl2 = "GL2a";
                                                    }
                                                    else
                                                    {
                                                        gl1 = "GL1";
                                                        gl2 = "GL2";
                                                    }
                                                }
                                                if (j == firstIndex - 1 && (m + 0.5 - numCap) * divCap <= leSeg && (m + 0.5 + numCap) * divCap >= leSeg && isDL)
                                                {
                                                    if (!tupGLLst.Exists(o => o.Item1 == "GL1b"))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>("GL1b", numCap * divCap, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>("GL1b", numCap * divCap, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == "GL1b");
                                                        dicGL[tu] += 1;
                                                    }
                                                }
                                                else
                                                {
                                                    if (!tupGLLst.Exists(o => o.Item1 == gl1))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>(gl1, numCap * divCap, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>(gl1, numCap * divCap, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == gl1);
                                                        dicGL[tu] += 1;
                                                    }
                                                }

                                                len1 = (m + 0.5) * divCap;
                                                no = m + 1;
                                            }
                                            //if ((m + 1) * divCap >= leSeg)
                                            if ((j < tupDimleLst.Count - 1 && (m + 1) * divCap >= leSeg) || (j == tupDimleLst.Count - 1 && (m + 1) * divCap >= leSeg + divCapLast))
                                            {
                                                if (m == num)
                                                {
                                                    if (!tupGLLst.Exists(o => o.Item1 == "GL5"))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>("GL5", last, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>("GL5", last, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == "GL5");
                                                        dicGL[tu] += 1;
                                                    }
                                                }
                                                else if (m + no1 == num)
                                                {
                                                    if ((m + 1) % 2 == 0)
                                                        isUp = false;
                                                    else
                                                        isUp = true;
                                                    if (!tupGLLst.Exists(o => o.Item1 == "GL5"))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>("GL5", last, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>("GL5", last, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == "GL5");
                                                        dicGL[tu] += 1;
                                                    }
                                                }
                                                else
                                                {

                                                    if ((m + 0.5) * divCap - len1 > 0)
                                                    {
                                                        double lenGl = (m + 0.5) * divCap - len1;
                                                        bool isExist = tupleGLLst.Exists(o => o.Item1 == gl6 && o.Item2 == lenGl);
                                                        if (!isExist)
                                                        {
                                                            int midNum = (int)(lenGl / divCap);
                                                            if ((m - midNum) % 2 == 0)
                                                                isUp = false;
                                                            else
                                                                isUp = true;
                                                            if (tupleGLLst.Count > 0)
                                                            {
                                                                if (gl6 == "GL6")
                                                                    gl6 = "GL7";
                                                                else if (gl6 == "GL7")
                                                                    gl6 = "GL8";
                                                            }
                                                            tupleGLLst.Add(new Tuple<string, double>(gl6, lenGl));
                                                        }

                                                        if (!tupGLLst.Exists(o => o.Item1 == gl6))
                                                        {
                                                            tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>(gl6, last, divHeight, dtSection.Rows[0], isUp));
                                                            dicGL.Add(new Tuple<string, double, double, DataRow, bool>(gl6, last, divHeight, dtSection.Rows[0], isUp), 1);
                                                        }
                                                        else
                                                        {
                                                            Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == gl6);
                                                            dicGL[tu] += 1;
                                                        }


                                                        len1 = (m + 0.5) * divCap;
                                                        no = m + 1;
                                                        break;
                                                    }
                                                }
                                              
                                            }
                                            #endregion
                                        }
                                        #endregion
                                    }
                                    else if ((m + 0.5) * divCap <= leSeg + divCap && tupDimleLst[j].Item2)
                                    {
                                        if ((m) * divCap <= leSeg - numGL2 * 0.5 * numCap * divCap - mid)
                                        {
                                            #region +1
                                            if ((m - no) % numCap == numCap - 1)
                                            {
                                                if (numCap == 3)
                                                {
                                                    if (numGL2 > 3)
                                                    {
                                                        if (gl2 == "GL2")
                                                        {
                                                            gl1 = "GL1a";
                                                            gl2 = "GL2a";
                                                        }
                                                        else
                                                        {
                                                            gl1 = "GL1";
                                                            gl2 = "GL2";
                                                        }
                                                    }
                                                   
                                                }
                                                if (j == firstIndex && isReAdd && (m) * divCap <= leSeg - numGL2 * numCap * 0.5 * divCap - mid)
                                                {
                                                    string gl = "GL2c";
                                                    if (gl2 == "GL2")
                                                    {
                                                        gl = "GL2c";
                                                    }
                                                    else
                                                        gl = "GL2b";
                                                    if (!tupGLLst.Exists(o => o.Item1 == gl))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>(gl, numCap * divCap, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>(gl, numCap * divCap, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == gl);
                                                        dicGL[tu] += 1;
                                                    }
                                                }
                                                else
                                                {
                                                    if (!tupGLLst.Exists(o => o.Item1 == gl2))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == gl2);
                                                        dicGL[tu] += 1;
                                                    }
                                                }
                                            
                                                no = m + 1;
                                            }
                                            #endregion
                                        }
                                        else if ((m) * divCap <= leSeg - numGL2 * 0.5 * numCap * divCap)
                                        {
                                            #region +2
                                            if ((m - no) == no2 - 1)
                                            {
                                                int midNum = (int)(mid / divCap);
                                                if ((m - midNum) % 2 != 0)
                                                    isUp = false;
                                                else
                                                    isUp = true;
                                                if (!tupGLLst.Exists(o => o.Item1 == "GL3"))
                                                {
                                                    tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>("GL3", mid, divHeight, dtSection.Rows[0], isUp));
                                                    dicGL.Add(new Tuple<string, double, double, DataRow, bool>("GL3", mid, divHeight, dtSection.Rows[0], isUp), 1);
                                                }
                                                else
                                                {
                                                    Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == "GL3");
                                                    dicGL[tu] += 1;
                                                }
                                                len1 = (m + 0.5) * divCap;
                                                no = m + 1;
                                                if (numCap == 3)
                                                {
                                                    if (numGL2 > 3)
                                                    {
                                                        if (gl2 == "GL2")
                                                        {
                                                            gl1 = "GL1a";
                                                            gl2 = "GL2a";
                                                          
                                                        }
                                                        else
                                                        {
                                                            gl1 = "GL1";
                                                            gl2 = "GL2";
                                                        }
                                                    }
                                                }
                                            }
                                            #endregion
                                        }
                                        else if ((m + 0.5) * divCap <= leSeg)
                                        {
                                            #region +3
                                            if ((m - no) % numCap == numCap - 1)
                                            {
                                                if (numCap == 3)
                                                {
                                                    if (numGL2 > 3)
                                                    {
                                                        if (gl2 == "GL2")
                                                        {
                                                            gl1 = "GL1a";
                                                            gl2 = "GL2a";
                                                        }
                                                        else
                                                        {
                                                            gl1 = "GL1";
                                                            gl2 = "GL2";
                                                        }
                                                       
                                                    }
                                                }
                                                if (j == lastIndex && isReAdd && (m) * divCap > leSeg - numCap * divCap * 2)
                                                {
                                                    string gl = "GL2d";
                                                    if (gl2 == "GL2")
                                                    {
                                                        gl = "GL2e";
                                                    }
                                                    else
                                                        gl = "GL2d";
                                                    if (!tupGLLst.Exists(o => o.Item1 == gl))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>(gl, numCap * divCap, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>(gl, numCap * divCap, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == gl);
                                                        dicGL[tu] += 1;
                                                    }
                                                }
                                                else
                                                {
                                                    if (!tupGLLst.Exists(o => o.Item1 == gl2))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == gl2);
                                                        dicGL[tu] += 1;
                                                    }
                                                }

                                                //gl2 = gl2.Replace("b", "");
                                                len1 = (m + 0.5) * divCap;
                                                no = m + 1;
                                            }
                                            #endregion
                                        }
                                        else
                                        {

                                            if ((m - no) % numCap == numCap - 1)
                                            {
                                                if (numCap == 3)
                                                {
                                                    if (numGL2 > 3)
                                                    {
                                                        if (gl2 == "GL2")
                                                        {
                                                            gl1 = "GL1a";
                                                            gl2 = "GL2a";
                                                        }
                                                        else
                                                        {
                                                            gl1 = "GL1";
                                                            gl2 = "GL2";
                                                        }                                  
                                                    }
                                                }
                                                if (j == lastIndex && isReAdd && (m) * divCap > leSeg - numCap * divCap * 2)
                                                {
                                                    string gl = "GL2d";
                                                    if (gl2 == "GL2")
                                                    {
                                                        gl = "GL2e";
                                                    }
                                                    else
                                                        gl = "GL2d";
                                                    if (!tupGLLst.Exists(o => o.Item1 == gl))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>(gl, numCap * divCap, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>(gl, numCap * divCap, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == gl);
                                                        dicGL[tu] += 1;
                                                    }
                                                }
                                                else
                                                {
                                                    if (!tupGLLst.Exists(o => o.Item1 == gl2))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == gl2);
                                                        dicGL[tu] += 1;
                                                    }
                                                }
                                                len1 = (m + 0.5) * divCap;
                                                no = m + 1;
                                                break;
                                            }
                                          
                                        }
                                    }
                                    if (m == num)
                                    {
                                        if (!tupGLLst.Exists(o => o.Item1 == "GL5"))
                                        {
                                            tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>("GL5", last, divHeight, dtSection.Rows[0], isUp));
                                            dicGL.Add(new Tuple<string, double, double, DataRow, bool>("GL5", last, divHeight, dtSection.Rows[0], isUp), 1);
                                        }
                                        else
                                        {                                           
                                            Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == "GL5");
                                            dicGL[tu] += 1;
                                        }
                                    }
                                }
                                #endregion
                                //Tuple<string, double, double, DataRow, bool> tuGL5 = tupGLLst.Find(o => o.Item1 == "GL5");
                                //if (tuGL5 != null)
                                //{
                                //    tupGLLst.Remove(tuGL5);
                                //    tupGLLst = tupGLLst.OrderBy(o => o.Item1).ToList();
                                //    tupGLLst.Add(tuGL5);
                                //}
                            }
                            else
                            {
                                if (bridgeW >= 4.5 * 1000)
                                {
                                    #region 常规 暂时和Y一致，4.5m(包含)以上桥宽
                                    if (m <= no1)
                                    {
                                        if (m == no1)
                                        {
                                            if (numCap == 3)
                                            {
                                                gl1 = "GL1a";
                                            }
                                            tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>("GL4", last, divHeight, dtSection.Rows[0], isUp));
                                            dicGL.Add(new Tuple<string, double, double, DataRow, bool>("GL4", last, divHeight, dtSection.Rows[0], isUp), 1);
                                            len1 = (m + 0.5) * divCap;
                                            no = no1 + 1;
                                        }
                                    }
                                    else
                                    {

                                        if ((m + 0.5) * divCap <= leSeg && !tupDimleLst[j].Item2)
                                        {
                                            if ((m - no) % numCap == numCap - 1)
                                            {
                                                if (numCap == 3)
                                                {
                                                    if (gl1 == "GL1")
                                                    {
                                                        gl1 = "GL1a";
                                                        gl2 = "GL2a";
                                                    }
                                                    else
                                                    {
                                                        gl1 = "GL1";
                                                        gl2 = "GL2";
                                                    }
                                                }
                                                if (!tupGLLst.Exists(o => o.Item1 == gl1))
                                                {
                                                    tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>(gl1, numCap * divCap, divHeight, dtSection.Rows[0], isUp));
                                                    dicGL.Add(new Tuple<string, double, double, DataRow, bool>(gl1, numCap * divCap, divHeight, dtSection.Rows[0], isUp), 1);
                                                }
                                                else
                                                {
                                                    Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == gl1);
                                                    dicGL[tu] += 1;
                                                }

                                                len1 = (m + 0.5) * divCap;
                                                no = m + 1;
                                            }
                                            //if ((m + 1) * divCap >= leSeg)
                                            if ((j < tupDimleLst.Count - 1 && (m + 1) * divCap >= leSeg) || (j == tupDimleLst.Count - 1 && (m + 1) * divCap >= leSeg + divCapLast))
                                            {
                                                if (m == num)
                                                {
                                                    if (!tupGLLst.Exists(o => o.Item1 == "GL5"))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>("GL5", last, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>("GL5", last, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == "GL5");
                                                        dicGL[tu] += 1;
                                                    }
                                                }
                                                else if (m + 1 == num)
                                                {
                                                    if ((m + 1) % 2 != 0)
                                                        isUp = false;
                                                    else
                                                        isUp = true;
                                                    if (!tupGLLst.Exists(o => o.Item1 == "GL5"))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>("GL5", last, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>("GL5", last, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == "GL5");
                                                        dicGL[tu] += 1;
                                                    }
                                                }
                                                else
                                                {

                                                    if ((m + 0.5) * divCap - len1 > 0)
                                                    {
                                                        double lenGl = (m + 0.5) * divCap - len1;
                                                        bool isExist = tupleGLLst.Exists(o => o.Item1 == gl6 && o.Item2 == lenGl);
                                                        if (!isExist)
                                                        {
                                                            int midNum = (int)(lenGl / divCap);
                                                            if ((m - midNum) % 2 != 0)
                                                                isUp = false;
                                                            else
                                                                isUp = true;
                                                            if (tupleGLLst.Count > 0)
                                                            {
                                                                if (gl6 == "GL6")
                                                                    gl6 = "GL7";
                                                                else if (gl6 == "GL7")
                                                                    gl6 = "GL8";
                                                            }
                                                            tupleGLLst.Add(new Tuple<string, double>(gl6, lenGl));
                                                            if (!tupGLLst.Exists(o => o.Item1 == gl6))
                                                            {
                                                                tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>(gl6, lenGl, divHeight, dtSection.Rows[0], isUp));
                                                                dicGL.Add(new Tuple<string, double, double, DataRow, bool>(gl6, lenGl, divHeight, dtSection.Rows[0], isUp), 1);
                                                            }
                                                            else
                                                            {
                                                                Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == gl6);
                                                                dicGL[tu] += 1;
                                                            }
                                                        }

                                                        len1 = (m + 0.5) * divCap;
                                                    }
                                                }
                                                break;
                                            }

                                        }
                                        else if ((m + 0.5) * divCap <= leSeg + divCap && tupDimleLst[j].Item2)
                                        {
                                            if ((m) * divCap <= leSeg - numGL2 * 0.5 * numCap * divCap - mid)
                                            {

                                                if ((m - no) % numCap == numCap - 1)
                                                {
                                                    if (numCap == 3)
                                                    {
                                                        if (numGL2 > 3)
                                                        {
                                                            if (gl2 == "GL2")
                                                            {
                                                                gl1 = "GL1a";
                                                                gl2 = "GL2a";
                                                            }
                                                            else
                                                            {
                                                                gl1 = "GL1";
                                                                gl2 = "GL2";
                                                            }
                                                        }
                                                    }
                                                    if (!tupGLLst.Exists(o => o.Item1 == gl2))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == gl2);
                                                        dicGL[tu] += 1;
                                                    }
                                                    no = m + 1;
                                                }
                                            }
                                            else if ((m) * divCap <= leSeg - numGL2 * 0.5 * numCap * divCap)
                                            {

                                                if ((m - no) == no2 - 1)
                                                {
                                                    int midNum = (int)(mid / divCap);
                                                    if ((m - midNum) % 2 != 0)
                                                        isUp = false;
                                                    else
                                                        isUp = true;
                                                    if (!tupGLLst.Exists(o => o.Item1 == "GL3"))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>("GL3", mid, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>("GL3", mid, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == "GL3");
                                                        dicGL[tu] += 1;
                                                    }
                                                    len1 = (m + 0.5) * divCap;
                                                    no = m + 1;
                                                    if (numCap == 3)
                                                    {
                                                        if (numGL2 > 3)
                                                        {
                                                            if (gl2 == "GL2")
                                                            {
                                                                gl1 = "GL1a";
                                                                gl2 = "GL2a";
                                                            }
                                                            else
                                                            {
                                                                gl1 = "GL1";
                                                                gl2 = "GL2";
                                                            }
                                                        }
                                                    }
                                                }

                                            }
                                            else if ((m + 0.5) * divCap <= leSeg)
                                            {
                                                if ((m - no) % numCap == numCap - 1)
                                                {
                                                    if (numCap == 3)
                                                    {
                                                        if (numGL2 > 3)
                                                        {
                                                            if (gl2 == "GL2")
                                                            {
                                                                gl1 = "GL1a";
                                                                gl2 = "GL2a";
                                                            }
                                                            else
                                                            {
                                                                gl1 = "GL1";
                                                                gl2 = "GL2";
                                                            }
                                                        }
                                                    }
                                                    if (!tupGLLst.Exists(o => o.Item1 == gl2))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == gl2);
                                                        dicGL[tu] += 1;
                                                    }


                                                    len1 = (m + 0.5) * divCap;
                                                    no = m + 1;
                                                }
                                            }
                                            else
                                            {

                                                if ((m - no) % numCap == numCap - 1)
                                                {
                                                    if (numCap == 3)
                                                    {
                                                        if (numGL2 > 3)
                                                        {
                                                            if (gl2 == "GL2")
                                                            {
                                                                gl1 = "GL1a";
                                                                gl2 = "GL2a";
                                                            }
                                                            else
                                                            {
                                                                gl1 = "GL1";
                                                                gl2 = "GL2";
                                                            }
                                                        }
                                                    }
                                                    if (!tupGLLst.Exists(o => o.Item1 == gl2))
                                                    {
                                                        tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp));
                                                        dicGL.Add(new Tuple<string, double, double, DataRow, bool>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == gl2);
                                                        dicGL[tu] += 1;
                                                    }

                                                    len1 = (m + 0.5) * divCap;
                                                    no = m + 1;
                                                    break;
                                                }
                                            }
                                        }
                                        if (m == num)
                                        {
                                            if (!tupGLLst.Exists(o => o.Item1 == "GL5"))
                                            {
                                                tupGLLst.Add(new Tuple<string, double, double, DataRow, bool>("GL5", last, divHeight, dtSection.Rows[0], isUp));
                                                dicGL.Add(new Tuple<string, double, double, DataRow, bool>("GL5", last, divHeight, dtSection.Rows[0], isUp), 1);
                                            }
                                            else
                                            {
                                                Tuple<string, double, double, DataRow, bool> tu = tupGLLst.Find(o => o.Item1 == "GL5");
                                                dicGL[tu] += 1;
                                            }
                                        }
                                    }
                                    #endregion
                                    Tuple<string, double, double, DataRow, bool> tuGL5 = tupGLLst.Find(o => o.Item1 == "GL5");
                                    if (tuGL5 != null)
                                    {
                                        tupGLLst.Remove(tuGL5);
                                        tupGLLst = tupGLLst.OrderBy(o => o.Item1).ToList();
                                        tupGLLst.Add(tuGL5);
                                    }
                                }
                                else
                                {
                                    int countGL = (int)((bridgeLength * 10 - (numCap - 0.5) * divCap) / (numCap * divCap));
                                    double la = bridgeLength * 10 - countGL * divCap * numCap - (numCap - 0.5) * divCap;
                                    double lastLen = la > divCap ? la : la + numCap * divCap;
                                    int count = (int)(lastLen / divCap);
                                    #region 4.5m以下
                                    if ((m) % numCap == numCap - 1 && m < num- count)
                                    {
                                        if (m == numCap - 1)
                                        {
                                            //if (numCap == 3)
                                            //{
                                            //    gl1 = "GL1a";
                                            //}
                                            len1 = (m + 0.5) * divCap;
                                           
                                            if ((m + 0.5) * divCap >= lenLight)
                                            {
                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>("GL3", len1, divHeight, dtSection.Rows[0], isUp, lenLight));
                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>("GL3", len1, divHeight, dtSection.Rows[0], isUp, lenLight), 1);
                                                lenLight += light_distinct;
                                            }
                                            else
                                            {
                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>("GL3", len1, divHeight, dtSection.Rows[0], isUp,0));
                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>("GL3", len1, divHeight, dtSection.Rows[0], isUp,0), 1);
                                            }
                                            no = no1 + 1;
                                        }
                                        else
                                        {
                                            //墩顶加强
                                            if (reinforced_straight_web_bar != straight_web_bar || reinforced_diagonal_brace != diagonal_brace)
                                            {

                                                #region //不同规格处理逻辑
                                                if ((m + 0.5) * divCap >= leSeg && j < tupDimleLst.Count - 1)
                                                {
                                                    if (tupDimleLst[j + 1].Item2)
                                                    {

                                                        double lenLast = leSeg - (m + 0.5) * divCap;

                                                        if ((int)(lenLast / divCap) == 0)
                                                        {
                                                            if (lenLast < 0)
                                                            {
                                                                bool isExist = tupleGLLst.Exists(o => o.Item2 == divCap);
                                                                if (!isExist)
                                                                {
                                                                    if (tupleGLLst.Count > 0)
                                                                    {
                                                                        if (gl5 == "GL5")
                                                                            gl5 = "GL6";
                                                                        else if (gl5 == "GL6")
                                                                            gl5 = "GL7";
                                                                        else if (gl5 == "GL7")
                                                                            gl5 = "GL8";
                                                                    }
                                                                    tupleGLLst.Add(new Tuple<string, double>(gl5, divCap));
                                                                    if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                    {
                                                                        if (tupleGLLstAll.Exists(o => o.Item1 == gl5) && tupleGLLstAll.FindAll((o) => o.Item1 == gl5).Count > 0)
                                                                        {
                                                                            //gl5 + "a"
                                                                            if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "'"))
                                                                            {
                                                                                double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                            }
                                                                            else
                                                                            {
                                                                                Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "'");
                                                                                dicAddGL[tuT] += 1;
                                                                            }
                                                                            tupleGLLstLightAll.Add(new Tuple<string, double>(gl5 + "'", divCap));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                            {
                                                                                double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                            }
                                                                            else
                                                                            {
                                                                                Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                                dicAddGL[tuT] += 1;
                                                                            }
                                                                            tupleGLLstLightAll.Add(new Tuple<string, double>(gl5, divCap));
                                                                        }
                                                                        lenLight += light_distinct;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (tupleGLLstLightAll.Exists(o => o.Item1 == gl5) && tupleGLLstLightAll.FindAll((o) => o.Item1 == gl5).Count > 0)
                                                                        {
                                                                            if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "'"))
                                                                            {
                                                                                //double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                            }
                                                                            else
                                                                            {
                                                                                Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "'");
                                                                                dicAddGL[tuT] += 1;
                                                                            }
                                                                            tupleGLLstAll.Add(new Tuple<string, double>(gl5 + "'", divCap));
                                                                        }
                                                                        else
                                                                        {
                                                                             //gl5
                                                                            if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                            {
                                                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                            }
                                                                            else
                                                                            {
                                                                                Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                                dicAddGL[tuT] += 1;
                                                                            }
                                                                            tupleGLLstAll.Add(new Tuple<string, double>(gl5, divCap));
                                                                        }
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (numCap == 3)
                                                                    {
                                                                        if ((m - numCap) % 2 == 0)
                                                                        {
                                                                            gl1 = "GL1a";
                                                                        }
                                                                        else
                                                                            gl1 = "GL1";
                                                                    }
                                                                    else
                                                                        gl1 = "GL1";
                                                                    if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                    {
                                                                        // "GL1a"
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl1 + "'"))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == gl1 + "'");
                                                                            dicAddGL[tu] += 1;
                                                                        }
                                                                        lenLight += light_distinct;
                                                                    }
                                                                    else
                                                                    {
                                                                        //"GL1"
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl1))
                                                                        {

                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == gl1);
                                                                            dicAddGL[tu] += 1;
                                                                        }
                                                                    }

                                                                }
                                                            }
                                                            else
                                                            {
                                                                Tuple<string, double> tu = tupleGLLst.Find(o => o.Item2 == divCap);
                                                                //if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                //{
                                                                //    //tu.Item1 + "a"
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "a"))
                                                                //    {
                                                                //        double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "a");
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //    lenLight += light_distinct;
                                                                //}
                                                                //else
                                                                //{
                                                                //    //tu.Item1
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                //    {
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //}
                                                                if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                {
                                                                    if (tupleGLLstAll.Exists(o => o.Item1 == tu.Item1) && tupleGLLstAll.FindAll((o) => o.Item1 == tu.Item1).Count > 0)
                                                                    {
                                                                        //gl5 + "a"
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "'"))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(tu.Item1 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(tu.Item1, divCap));
                                                                    }
                                                                    lenLight += light_distinct;
                                                                }
                                                                else
                                                                {
                                                                    if (tupleGLLstLightAll.Exists(o => o.Item1 == tu.Item1) && tupleGLLstLightAll.FindAll((o) => o.Item1 == tu.Item1).Count > 0)
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "'"))
                                                                        {
                                                                            //double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(tu.Item1 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        //gl5
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                        {
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(tu.Item1, divCap));
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else if ((int)(lenLast / divCap) == -1)
                                                        {
                                                            bool isExist = tupleGLLst.Exists(o => o.Item2 == divCap * 2);
                                                            if (!isExist)
                                                            {
                                                                if (tupleGLLst.Count > 0)
                                                                {
                                                                    if (gl5 == "GL5")
                                                                        gl5 = "GL6";
                                                                    else if (gl5 == "GL6")
                                                                        gl5 = "GL7";
                                                                    else if (gl5 == "GL7")
                                                                        gl5 = "GL8";
                                                                }
                                                                tupleGLLst.Add(new Tuple<string, double>(gl5, divCap * 2));
                                                                //if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                //{
                                                                //    //gl5 + "a"
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "a"))
                                                                //    {
                                                                //        double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "a");
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //    lenLight += light_distinct;
                                                                //}
                                                                //else
                                                                //{
                                                                //    //gl5
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                //    {
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //}
                                                                if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                {
                                                                    if (tupleGLLstAll.Exists(o => o.Item1 == gl5) && tupleGLLstAll.FindAll((o) => o.Item1 == gl5).Count > 0)
                                                                    {
                                                                        //gl5 + "a"
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "'"))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(gl5 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(gl5, divCap));
                                                                    }
                                                                    lenLight += light_distinct;
                                                                }
                                                                else
                                                                {
                                                                    if (tupleGLLstLightAll.Exists(o => o.Item1 == gl5) && tupleGLLstLightAll.FindAll((o) => o.Item1 == gl5).Count > 0)
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "'"))
                                                                        {
                                                                            //double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(gl5 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        //gl5
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                        {
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(gl5, divCap));
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                Tuple<string, double> tu = tupleGLLst.Find(o => o.Item2 == divCap * 2);
                                                                //if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                //{
                                                                //    //tu.Item1 + "a"
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "a"))
                                                                //    {
                                                                //        double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp,lenL));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "a");
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //    lenLight += light_distinct;
                                                                //}
                                                                //else
                                                                //{
                                                                //    //tu.Item1
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                //    {
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //}
                                                                if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                {
                                                                    if (tupleGLLstAll.Exists(o => o.Item1 == tu.Item1) && tupleGLLstAll.FindAll((o) => o.Item1 == tu.Item1).Count > 0)
                                                                    {
                                                                        //gl5 + "a"
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "'"))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(tu.Item1 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(tu.Item1, divCap));
                                                                    }
                                                                    lenLight += light_distinct;
                                                                }
                                                                else
                                                                {
                                                                    if (tupleGLLstLightAll.Exists(o => o.Item1 == tu.Item1) && tupleGLLstLightAll.FindAll((o) => o.Item1 == tu.Item1).Count > 0)
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "'"))
                                                                        {
                                                                            //double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(tu.Item1 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        //gl5
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                        {
                                                                            //double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(tu.Item1, divCap));
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else if ((int)(lenLast / divCap) == -2)
                                                        {
                                                            bool isExist = tupleGLLst.Exists(o => o.Item2 == divCap * 3);
                                                            if (!isExist)
                                                            {
                                                                if (tupleGLLst.Count > 0)
                                                                {
                                                                    if (gl5 == "GL5")
                                                                        gl5 = "GL6";
                                                                    else if (gl5 == "GL6")
                                                                        gl5 = "GL7";
                                                                    else if (gl5 == "GL7")
                                                                        gl5 = "GL8";
                                                                }
                                                                tupleGLLst.Add(new Tuple<string, double>(gl5, divCap * 3));
                                                                //if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                //{
                                                                //    //gl5 + "a"
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "a"))
                                                                //    {
                                                                //        double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "a");
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //    lenLight += light_distinct;
                                                                //}
                                                                //else
                                                                //{
                                                                //    //gl5
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                //    {
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //}
                                                                if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                {
                                                                    if (tupleGLLstAll.Exists(o => o.Item1 == gl5) && tupleGLLstAll.FindAll((o) => o.Item1 == gl5).Count > 0)
                                                                    {
                                                                        //gl5 + "a"
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "'"))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(gl5 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(gl5, divCap));
                                                                    }
                                                                    lenLight += light_distinct;
                                                                }
                                                                else
                                                                {
                                                                    if (tupleGLLstLightAll.Exists(o => o.Item1 == gl5) && tupleGLLstLightAll.FindAll((o) => o.Item1 == gl5).Count > 0)
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "'"))
                                                                        {
                                                                            //double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(gl5 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        //gl5
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                        {
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(gl5, divCap));
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                Tuple<string, double> tu = tupleGLLst.Find(o => o.Item2 == divCap * 3);
                                                                //if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                //{
                                                                //    //tu.Item1 + "a"
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "a"))
                                                                //    {
                                                                //        double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "a");
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //    lenLight += light_distinct;
                                                                //}
                                                                //else
                                                                //{
                                                                //    //tu.Item1
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                //    {
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //}
                                                                if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                {
                                                                    if (tupleGLLstAll.Exists(o => o.Item1 == tu.Item1) && tupleGLLstAll.FindAll((o) => o.Item1 == tu.Item1).Count > 0)
                                                                    {
                                                                        //gl5 + "a"
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "'"))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(tu.Item1 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(tu.Item1, divCap));
                                                                    }
                                                                    lenLight += light_distinct;
                                                                }
                                                                else
                                                                {
                                                                    if (tupleGLLstLightAll.Exists(o => o.Item1 == tu.Item1) && tupleGLLstLightAll.FindAll((o) => o.Item1 == tu.Item1).Count > 0)
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "'"))
                                                                        {
                                                                            //double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(tu.Item1 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        //gl5
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                        {
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(tu.Item1, divCap));
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (numCap == 3)
                                                            {
                                                                if ((m - numCap) % 2 == 0)
                                                                {
                                                                    gl2 = "GL2a";
                                                                }
                                                                else
                                                                    gl2 = "GL2";
                                                            }
                                                            else
                                                                gl2 = "GL2";
                                                            if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                            {
                                                                //"GL2a"
                                                                if (!tupAddGLLst.Exists(o => o.Item1 == gl2 + "'"))
                                                                {
                                                                    double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                    tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl2 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                    dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl2 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                }
                                                                else
                                                                {
                                                                    Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl2 + "'");
                                                                    dicAddGL[tuT] += 1;
                                                                }
                                                                lenLight += light_distinct;
                                                            }
                                                            else
                                                            {
                                                                //"GL2"
                                                                if (!tupAddGLLst.Exists(o => o.Item1 == gl2))
                                                                {
                                                                    tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0));
                                                                    dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0), 1);
                                                                }
                                                                else
                                                                {
                                                                    Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl2);
                                                                    dicAddGL[tuT] += 1;
                                                                }
                                                            }
                                                        }
                                                        no = m + 1;
                                                        break;
                                                    }
                                                    else
                                                    {
                                                        //pt2 = dPt1.C2D((m - 2.5) * divCap, -(m - 2.5) * divCap * bridgeSlope);
                                                        double lenLast = leSeg - (m - 0.5) * divCap;
                                                        if ((int)(lenLast / divCap) == 0)
                                                        {
                                                            if (lenLast < 0)
                                                            {
                                                                bool isExist = tupleGLLst.Exists(o => o.Item2 == divCap * (numCap - 1));
                                                                if (!isExist)
                                                                {
                                                                    if (tupleGLLst.Count > 0)
                                                                    {
                                                                        if (gl5 == "GL5")
                                                                            gl5 = "GL6";
                                                                        else if (gl5 == "GL6")
                                                                            gl5 = "GL7";
                                                                        else if (gl5 == "GL7")
                                                                            gl5 = "GL8";
                                                                    }
                                                                    tupleGLLst.Add(new Tuple<string, double>(gl5, divCap * (numCap - 1)));
                                                                    //if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                    //{
                                                                    //    //gl5 + "a"
                                                                    //    if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "a"))
                                                                    //    {
                                                                    //        double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                    //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                    //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                    //    }
                                                                    //    else
                                                                    //    {
                                                                    //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "a");
                                                                    //        dicAddGL[tuT] += 1;
                                                                    //    }
                                                                    //    lenLight += light_distinct;
                                                                    //}
                                                                    //else
                                                                    //{
                                                                    //    //gl5
                                                                    //    if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                    //    {
                                                                    //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                    //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                    //    }
                                                                    //    else
                                                                    //    {
                                                                    //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                    //        dicAddGL[tuT] += 1;
                                                                    //    }
                                                                    //}
                                                                    if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                    {
                                                                        if (tupleGLLstAll.Exists(o => o.Item1 == gl5) && tupleGLLstAll.FindAll((o) => o.Item1 == gl5).Count > 0)
                                                                        {
                                                                            //gl5 + "a"
                                                                            if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "'"))
                                                                            {
                                                                                double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                            }
                                                                            else
                                                                            {
                                                                                Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "'");
                                                                                dicAddGL[tuT] += 1;
                                                                            }
                                                                            tupleGLLstLightAll.Add(new Tuple<string, double>(gl5 + "'", divCap));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                            {
                                                                                double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                            }
                                                                            else
                                                                            {
                                                                                Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                                dicAddGL[tuT] += 1;
                                                                            }
                                                                            tupleGLLstLightAll.Add(new Tuple<string, double>(gl5, divCap));
                                                                        }
                                                                        lenLight += light_distinct;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (tupleGLLstLightAll.Exists(o => o.Item1 == gl5) && tupleGLLstLightAll.FindAll((o) => o.Item1 == gl5).Count > 0)
                                                                        {
                                                                            if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "'"))
                                                                            {
                                                                                //double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                            }
                                                                            else
                                                                            {
                                                                                Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "'");
                                                                                dicAddGL[tuT] += 1;
                                                                            }
                                                                            tupleGLLstAll.Add(new Tuple<string, double>(gl5 + "'", divCap));
                                                                        }
                                                                        else
                                                                        {
                                                                            //gl5
                                                                            if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                            {
                                                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                            }
                                                                            else
                                                                            {
                                                                                Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                                dicAddGL[tuT] += 1;
                                                                            }
                                                                            tupleGLLstAll.Add(new Tuple<string, double>(gl5, divCap));
                                                                        }
                                                                    }
                                                                }


                                                                else
                                                                {
                                                                    Tuple<string, double> tu = tupleGLLst.Find(o => o.Item2 == divCap * (numCap - 1));
                                                                    //if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                    //{
                                                                    //    //tu.Item1 + "a"
                                                                    //    if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "a"))
                                                                    //    {
                                                                    //        double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                    //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                    //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                    //    }
                                                                    //    else
                                                                    //    {
                                                                    //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "a");
                                                                    //        dicAddGL[tuT] += 1;
                                                                    //    }
                                                                    //    lenLight += light_distinct;
                                                                    //}
                                                                    //else
                                                                    //{
                                                                    //    //tu.Item1
                                                                    //    if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                    //    {

                                                                    //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                    //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                    //    }
                                                                    //    else
                                                                    //    {
                                                                    //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                    //        dicAddGL[tuT] += 1;
                                                                    //    }
                                                                    //}
                                                                    if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                    {
                                                                        if (tupleGLLstAll.Exists(o => o.Item1 == tu.Item1) && tupleGLLstAll.FindAll((o) => o.Item1 == tu.Item1).Count > 0)
                                                                        {
                                                                            //gl5 + "a"
                                                                            if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "'"))
                                                                            {
                                                                                double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                            }
                                                                            else
                                                                            {
                                                                                Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "'");
                                                                                dicAddGL[tuT] += 1;
                                                                            }
                                                                            tupleGLLstLightAll.Add(new Tuple<string, double>(tu.Item1 + "'", divCap));
                                                                        }
                                                                        else
                                                                        {
                                                                            if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                            {
                                                                                double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                            }
                                                                            else
                                                                            {
                                                                                Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                                dicAddGL[tuT] += 1;
                                                                            }
                                                                            tupleGLLstLightAll.Add(new Tuple<string, double>(tu.Item1, divCap));
                                                                        }
                                                                        lenLight += light_distinct;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (tupleGLLstLightAll.Exists(o => o.Item1 == tu.Item1) && tupleGLLstLightAll.FindAll((o) => o.Item1 == tu.Item1).Count > 0)
                                                                        {
                                                                            if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "'"))
                                                                            {
                                                                                //double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                            }
                                                                            else
                                                                            {
                                                                                Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "'");
                                                                                dicAddGL[tuT] += 1;
                                                                            }
                                                                            tupleGLLstAll.Add(new Tuple<string, double>(tu.Item1 + "'", divCap));
                                                                        }
                                                                        else
                                                                        {
                                                                            //gl5
                                                                            if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                            {
                                                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                            }
                                                                            else
                                                                            {
                                                                                Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                                dicAddGL[tuT] += 1;
                                                                            }
                                                                            tupleGLLstAll.Add(new Tuple<string, double>(tu.Item1, divCap));
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if (numCap == 3)
                                                                {
                                                                    if ((m - numCap) % 2 == 0)
                                                                    {
                                                                        gl2 = "GL2a";
                                                                    }
                                                                    else
                                                                        gl2 = "GL2";
                                                                }
                                                                else
                                                                    gl2 = "GL2";
                                                                if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                {
                                                                    //"GL2a"
                                                                    if (!tupAddGLLst.Exists(o => o.Item1 == gl2+"'"))
                                                                    {
                                                                        double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl2 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl2 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                    }
                                                                    else
                                                                    {
                                                                        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl2 + "'");
                                                                        dicAddGL[tuT] += 1;
                                                                    }
                                                                    lenLight += light_distinct;
                                                                }
                                                                else
                                                                {
                                                                    //"GL2"
                                                                    if (!tupAddGLLst.Exists(o => o.Item1 == gl2))
                                                                    {
                                                                        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                    }
                                                                    else
                                                                    {
                                                                        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl2);
                                                                        dicAddGL[tuT] += 1;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else if ((int)(lenLast / divCap) == -1)
                                                        {
                                                            bool isExist = tupleGLLst.Exists(o => o.Item2 == divCap * (numCap - 2));
                                                            if (!isExist)
                                                            {
                                                                if (tupleGLLst.Count > 0)
                                                                {
                                                                    if (gl5 == "GL5")
                                                                        gl5 = "GL6";
                                                                    else if (gl5 == "GL6")
                                                                        gl5 = "GL7";
                                                                    else if (gl5 == "GL7")
                                                                        gl5 = "GL8";
                                                                }
                                                                tupleGLLst.Add(new Tuple<string, double>(gl5, divCap * (numCap - 2)));
                                                                //if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                //{
                                                                //    //gl5 + "a"
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "a"))
                                                                //    {
                                                                //        double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "a");
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //    lenLight += light_distinct;
                                                                //}
                                                                //else
                                                                //{
                                                                //    //gl5
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                //    {
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //}
                                                                if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                {
                                                                    if (tupleGLLstAll.Exists(o => o.Item1 == gl5) && tupleGLLstAll.FindAll((o) => o.Item1 == gl5).Count > 0)
                                                                    {
                                                                        //gl5 + "a"
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "'"))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(gl5 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(gl5, divCap));
                                                                    }
                                                                    lenLight += light_distinct;
                                                                }
                                                                else
                                                                {
                                                                    if (tupleGLLstLightAll.Exists(o => o.Item1 == gl5) && tupleGLLstLightAll.FindAll((o) => o.Item1 == gl5).Count > 0)
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "'"))
                                                                        {
                                                                            //double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(gl5 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        //gl5
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                        {
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(gl5, divCap));
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                Tuple<string, double> tu = tupleGLLst.Find(o => o.Item2 == divCap * (numCap - 2));
                                                                //if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                //{
                                                                //    //tu.Item1 + "a"
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "a"))
                                                                //    {
                                                                //        double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "a");
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //    lenLight += light_distinct;
                                                                //}
                                                                //else
                                                                //{
                                                                //    //tu.Item1
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                //    {
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //}
                                                                if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                {
                                                                    if (tupleGLLstAll.Exists(o => o.Item1 == tu.Item1) && tupleGLLstAll.FindAll((o) => o.Item1 == tu.Item1).Count > 0)
                                                                    {
                                                                        //gl5 + "a"
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "'"))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(tu.Item1 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(tu.Item1, divCap));
                                                                    }
                                                                    lenLight += light_distinct;
                                                                }
                                                                else
                                                                {
                                                                    if (tupleGLLstLightAll.Exists(o => o.Item1 == tu.Item1) && tupleGLLstLightAll.FindAll((o) => o.Item1 == tu.Item1).Count > 0)
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "'"))
                                                                        {
                                                                            //double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(tu.Item1 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        //gl5
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                        {
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(tu.Item1, divCap));
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else if ((int)(lenLast / divCap) == -2)
                                                        {
                                                            bool isExist = tupleGLLst.Exists(o => o.Item2 == divCap * (numCap - 3));
                                                            if (!isExist)
                                                            {
                                                                if (tupleGLLst.Count > 0)
                                                                {
                                                                    if (gl5 == "GL5")
                                                                        gl5 = "GL6";
                                                                    else if (gl5 == "GL6")
                                                                        gl5 = "GL7";
                                                                    else if (gl5 == "GL7")
                                                                        gl5 = "GL8";
                                                                }
                                                                tupleGLLst.Add(new Tuple<string, double>(gl5, divCap * (numCap - 3)));
                                                                //if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                //{
                                                                //    //gl5 + "a"
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "a"))
                                                                //    {
                                                                //        double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "a");
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //    lenLight += light_distinct;
                                                                //}
                                                                //else
                                                                //{
                                                                //    //gl5
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                //    {
                                                                //        double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //}
                                                                if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                {
                                                                    if (tupleGLLstAll.Exists(o => o.Item1 == gl5) && tupleGLLstAll.FindAll((o) => o.Item1 == gl5).Count > 0)
                                                                    {
                                                                        //gl5 + "a"
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "'"))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(gl5 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(gl5, divCap));
                                                                    }
                                                                    lenLight += light_distinct;
                                                                }
                                                                else
                                                                {
                                                                    if (tupleGLLstLightAll.Exists(o => o.Item1 == gl5) && tupleGLLstLightAll.FindAll((o) => o.Item1 == gl5).Count > 0)
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5 + "'"))
                                                                        {
                                                                            //double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(gl5 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        //gl5
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl5))
                                                                        {
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl5, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == gl5);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(gl5, divCap));
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                Tuple<string, double> tu = tupleGLLst.Find(o => o.Item2 == divCap * (numCap - 3));
                                                                //if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                //{
                                                                //    //tu.Item1 + "a"
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "a"))
                                                                //    {
                                                                //        double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp,lenL));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp,lenL), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "a");
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //    lenLight += light_distinct;
                                                                //}
                                                                //else
                                                                //{
                                                                //    //tu.Item1
                                                                //    if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                //    {
                                                                //        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0));
                                                                //        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0), 1);
                                                                //    }
                                                                //    else
                                                                //    {
                                                                //        Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                //        dicAddGL[tuT] += 1;
                                                                //    }
                                                                //}
                                                                if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                                {
                                                                    if (tupleGLLstAll.Exists(o => o.Item1 == tu.Item1) && tupleGLLstAll.FindAll((o) => o.Item1 == tu.Item1).Count > 0)
                                                                    {
                                                                        //gl5 + "a"
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "'"))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(tu.Item1 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                        {
                                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstLightAll.Add(new Tuple<string, double>(tu.Item1, divCap));
                                                                    }
                                                                    lenLight += light_distinct;
                                                                }
                                                                else
                                                                {
                                                                    if (tupleGLLstLightAll.Exists(o => o.Item1 == tu.Item1) && tupleGLLstLightAll.FindAll((o) => o.Item1 == tu.Item1).Count > 0)
                                                                    {
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1 + "'"))
                                                                        {
                                                                            //double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1 + "'");
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(tu.Item1 + "'", divCap));
                                                                    }
                                                                    else
                                                                    {
                                                                        //gl5
                                                                        if (!tupAddGLLst.Exists(o => o.Item1 == tu.Item1))
                                                                        {
                                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(tu.Item1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                        }
                                                                        else
                                                                        {
                                                                            Tuple<string, double, double, DataRow, bool, double> tuT = tupAddGLLst.Find(o => o.Item1 == tu.Item1);
                                                                            dicAddGL[tuT] += 1;
                                                                        }
                                                                        tupleGLLstAll.Add(new Tuple<string, double>(tu.Item1, divCap));
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (numCap == 3)
                                                            {
                                                                if ((m - numCap) % 2 == 0)
                                                                {
                                                                    gl1 = "GL1a";
                                                                }
                                                                else
                                                                    gl1 = "GL1";
                                                            }
                                                            else
                                                                gl1 = "GL1";
                                                            if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                            {
                                                                // "GL1a"
                                                                if (!tupAddGLLst.Exists(o => o.Item1 == gl1+"'"))
                                                                {
                                                                    double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                    tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp,lenL));
                                                                    dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp,lenL), 1);
                                                                }
                                                                else
                                                                {
                                                                    Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == gl1 + "'");
                                                                    dicAddGL[tu] += 1;
                                                                }
                                                                lenLight += light_distinct;
                                                            }
                                                            else
                                                            {
                                                                //"GL1"
                                                                if (!tupAddGLLst.Exists(o => o.Item1 == gl1))
                                                                {
                                             
                                                                    tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl1, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0));
                                                                    dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl1, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0), 1);
                                                                }
                                                                else
                                                                {
                                                                    Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == gl1);
                                                                    dicAddGL[tu] += 1;
                                                                }
                                                            }

                                                        }
                                                        no = m + 1;
                                                        break;
                                                    }
                                                }
                                                else
                                                {

                                                    if (tupDimleLst[j].Item2)
                                                    {
                                                        if (numCap == 3)
                                                        {
                                                            if ((m - numCap) % 2 == 0)
                                                            {
                                                                gl2 = "GL2a";
                                                            }
                                                            else
                                                                gl2 = "GL2";
                                                        }
                                                        else
                                                            gl2 = "GL2";
                                                        //if (numCap == 3)
                                                        //{
                                                        if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                        {
                                                            //"GL2a"
                                                            if (!tupAddGLLst.Exists(o => o.Item1 == gl2 + "'"))
                                                            {
                                                                double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl2 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl2 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                            }
                                                            else
                                                            {
                                                                Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == gl2 + "'");
                                                                dicAddGL[tu] += 1;
                                                            }
                                                            lenLight += light_distinct;
                                                        }
                                                        else
                                                        {
                                                            //gl2
                                                            if (!tupAddGLLst.Exists(o => o.Item1 == gl2))
                                                            {
                                                                tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl2, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                            }
                                                            else
                                                            {
                                                                Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == "GL2");
                                                                dicAddGL[tu] += 1;
                                                            }
                                                        }
                                                        //}
                                                        //else
                                                        //{
                                                        //    if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                        //    {
                                                        //        //"GL2a"
                                                        //        if (!tupAddGLLst.Exists(o => o.Item1 == "GL2a"))
                                                        //        {
                                                        //            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                        //            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>("GL2a", numCap * divCap, divHeight, dtSection.Rows[0], isUp,lenL));
                                                        //            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>("GL2a", numCap * divCap, divHeight, dtSection.Rows[0], isUp,lenL), 1);
                                                        //        }
                                                        //        else
                                                        //        {
                                                        //            Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == "GL2a");
                                                        //            dicAddGL[tu] += 1;
                                                        //        }
                                                        //        lenLight += light_distinct;
                                                        //    }
                                                        //    else
                                                        //    {
                                                        //        if (!tupAddGLLst.Exists(o => o.Item1 == "GL2"))
                                                        //        {

                                                        //            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>("GL2", numCap * divCap, divHeight, dtSection.Rows[0], isUp,0));
                                                        //            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>("GL2", numCap * divCap, divHeight, dtSection.Rows[0], isUp,0), 1);
                                                        //        }
                                                        //        else
                                                        //        {
                                                        //            Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == "GL2");
                                                        //            dicAddGL[tu] += 1;
                                                        //        }
                                                        //        //"GL2"
                                                        //    }
                                                        //}
                                                    }
                                                    else
                                                    {
                                                        if (numCap == 3)
                                                        {
                                                            if ((m - numCap) % 2 == 0)
                                                            {
                                                                gl1 = "GL1a";
                                                            }
                                                            else
                                                                gl1 = "GL1";
                                                        }
                                                        else
                                                            gl1 = "GL1";
                                                        //if (numCap == 3)
                                                        //{
                                                            if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                            {
                                                                //"GL1a"
                                                                if (!tupAddGLLst.Exists(o => o.Item1 == gl1+"'"))
                                                                {
                                                                    double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                    tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                                    dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl1 + "'", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                                }
                                                                else
                                                                {
                                                                    Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == gl1 + "'");
                                                                    dicAddGL[tu] += 1;
                                                                }
                                                                lenLight += light_distinct;
                                                            }
                                                            else
                                                            {
                                                                if (!tupAddGLLst.Exists(o => o.Item1 == gl1))
                                                                {
                                                                    //double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                                    tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                                    dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl1, numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                                }
                                                                else
                                                                {
                                                                    Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == gl1);
                                                                    dicAddGL[tu] += 1;
                                                                }
                                                                //gl1
                                                            }
                                                        //}
                                                        //else
                                                        //{
                                                        //    if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                        //    {
                                                        //        double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                        //        //"GL1a"
                                                        //        if (!tupAddGLLst.Exists(o => o.Item1 == "GL1a"))
                                                        //        {
                                                        //            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>("GL1a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                        //            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>("GL1a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                        //        }
                                                        //        else
                                                        //        {
                                                        //            Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == "GL1a");
                                                        //            dicAddGL[tu] += 1;
                                                        //        }
                                                        //        lenLight += light_distinct;
                                                        //    }
                                                        //    else
                                                        //    {
                                                        //        if (!tupAddGLLst.Exists(o => o.Item1 == "GL1"))
                                                        //        {
                                                        //            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>("GL1", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0));
                                                        //            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>("GL1", numCap * divCap, divHeight, dtSection.Rows[0], isUp, 0), 1);
                                                        //        }
                                                        //        else
                                                        //        {
                                                        //            Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == "GL1");
                                                        //            dicAddGL[tu] += 1;
                                                        //        }
                                                        //        //"GL1"
                                                        //    }
                                                        //}
                                                    }
                                                }
                                                #endregion

                                            }
                                            else  //墩顶区不加强
                                            {
                                                #region //相同规格处理逻辑
                                                string gl = "GL1";
                                                if (numCap == 3)
                                                {
                                                    if (gl == "GL1")
                                                    {
                                                        gl = "GL2";
                                                    }
                                                    else
                                                    {
                                                        gl = "GL1";
                                                    }
                                                }
                                                if ((m + 0.5) * divCap >= lenLight || (m + 0.5 - numCap) * divCap >= lenLight)
                                                {

                                                    if (numCap == 3)
                                                    {
                                                        //gl + "a"
                                                        if (!tupAddGLLst.Exists(o => o.Item1 == gl + "a"))
                                                        {
                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL));
                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl + "a", numCap * divCap, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                                        }
                                                        else
                                                        {
                                                            Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == gl + "a");
                                                            dicAddGL[tu] += 1;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        //"GL2"
                                                        if (!tupAddGLLst.Exists(o => o.Item1 == "GL2"))
                                                        {
                                                            double lenL = lenLight - (m + 0.5 - numCap) * divCap;
                                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>("GL2", numCap * divCap, divHeight, dtSection.Rows[0], isUp,lenL));
                                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>("GL2", numCap * divCap, divHeight, dtSection.Rows[0], isUp,lenL), 1);
                                                        }
                                                        else
                                                        {
                                                            Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == "GL2");
                                                            dicAddGL[tu] += 1;
                                                        }
                                                    }
                                                    lenLight += light_distinct;
                                                }
                                                else
                                                {
                                                    //gl
                                                    if (!tupAddGLLst.Exists(o => o.Item1 == gl))
                                                    {
                                                        tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>(gl, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0));
                                                        dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>(gl, numCap * divCap, divHeight, dtSection.Rows[0], isUp,0), 1);
                                                    }
                                                    else
                                                    {
                                                        Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == gl);
                                                        dicAddGL[tu] += 1;
                                                    }
                                                }
                                                no = m + 1;
                                                #endregion
                                            }
                                        }
                                    }
                                    else if (m == num) //终点位置
                                    {

                                        if ((m - count-1) % 2 == 0)
                                            isUp = false;
                                        else
                                            isUp = true;
                                        if ((m) * divCap >= lenLight || (m) * divCap- lastLen >= lenLight)
                                        {
                                            double lenL = lenLight - (m - count-0.5) * divCap;
                                            tupAddGLLst.Add(new Tuple<string, double, double, DataRow, bool, double>("GL4", lastLen, divHeight, dtSection.Rows[0], isUp, lenL));
                                            dicAddGL.Add(new Tuple<string, double, double, DataRow, bool, double>("GL4", lastLen, divHeight, dtSection.Rows[0], isUp, lenL), 1);
                                        }
                                        else
                                        {
                                            //Tuple<string, double, double, DataRow, bool, double> tu = tupAddGLLst.Find(o => o.Item1 == "GL4");
                                            //dicAddGL[tu] += 1;
                                        }
                                        no = m + 1;
                                    }
                                    #endregion
                                    tupGLLst = tupGLLst.OrderBy(o => o.Item1).ToList();
                                   
                                }
                            }
                        }
                    }
                  
                    dicGL = dicGL.OrderBy(p => p.Key.Item1).ToDictionary(p => p.Key, o => o.Value);
                    tupAddGLLst = tupAddGLLst.OrderBy(o => o.Item1).ToList();
                    dicAddGL = dicAddGL.OrderBy(p => p.Key.Item1).ToDictionary(p => p.Key, o => o.Value);
                    #endregion
                    System.Data.DataTable dtQuatity = new System.Data.DataTable();
                    dtQuatity.Columns.Add("material", typeof(string));
                    dtQuatity.Columns.Add("material_specs", typeof(string));
                    dtQuatity.Columns.Add("material_code", typeof(string));
                    dtQuatity.Columns.Add("member", typeof(string));
                    dtQuatity.Columns.Add("member_type", typeof(string));
                    dtQuatity.Columns.Add("member_length", typeof(string));
                    dtQuatity.Columns.Add("member_lvolume", typeof(string));
                    dtQuatity.Columns.Add("unit", typeof(string));
                    dtQuatity.Columns.Add("count", typeof(string));
                    dtQuatity.Columns.Add("member_weight", typeof(string));                  
                    dtQuatity.Columns.Add("total_weight", typeof(string));
                    dtQuatity.Columns.Add("total_count", typeof(string));
                    dtQuatity.Columns.Add("glname", typeof(string));

                    string file = "";
                    List<string> fileList = new List<string>();
                    if (!string.IsNullOrWhiteSpace(_appPath))
                        appPath = _appPath;
                    DrawingConfigModel drawingConfigModel = new DrawingConfigModel();
                    if (tupGLLst.Count > 0)
                    {
                        #region 桥面宽度大于4.5m(包含)
                        int pageNum = tupGLLst.Count / 2;
                        if (tupGLLst.Count - pageNum * 2 > 0)
                            pageNum = pageNum + 1;
                        else
                        {
                            if(divCapLast>0)
                               pageNum = pageNum+1;
                        }
                        int tableNum = tupGLLst.Count / 6;
                        if (tupGLLst.Count - tableNum * 6 > 0)
                            tableNum = tableNum + 1;
                        for (int i = 0; i < pageNum + tableNum; i++)
                        {
                            if (i < pageNum)
                            {
                                using (Services svc = new Services())
                                {
                                    SystemObjects.DynamicLinker.LoadApp("GripPoints", false, false);
                                    SystemObjects.DynamicLinker.LoadApp("PlotSettingsValidator", false, false);

                                    HostApplicationServices.Current = new HostAppServ(svc);
                                    Environment.SetEnvironmentVariable("DDPLOTSTYLEPATHS", ((HostAppServ)HostApplicationServices.Current).FindConfigPath(String.Format("PrinterStyleSheetDir")));
                                    using (Database db = new Database())
                                    {
                                        HostApplicationServices.WorkingDatabase = db;

                                        //db = new Database();
                                        InitConfig.InitStandardConfig(db, bridgeId);
                                        //if (i < start + 2)
                                        //    P1.DrawingSteelTrussBeamByGL(db, bridgeId, catalogid, i + 1, tupGLLst.Count, out dtProjectConfig, bridgeW, bridgeSlope, divCap, divHeight, tupGLLst[i].Item2, tupGLLst[i].Item1, tupGLLst[i].Item4);
                                        //else
                                        if (divCapLast > 0)
                                        {
                                            Tuple<string, double, double, DataRow, bool> tuGL5 = tupGLLst.Find(o => o.Item1 == "GL5");
                                            List<Tuple<string, double, double, DataRow, bool>> tupGLLstGL5 = new List<Tuple<string, double, double, DataRow, bool>>();
                                            List<Tuple<string, double, double, DataRow, bool>> tupGLLstGLNormoul = new List<Tuple<string, double, double, DataRow, bool>>();
                                            if (tuGL5 != null)
                                            {
                                                tupGLLst.Remove(tuGL5);
                                                tupGLLstGLNormoul = tupGLLst;
                                                tupGLLst = tupGLLst.OrderBy(o => o.Item1).ToList();
                                                tupGLLst.Add(tuGL5);
                                                tupGLLstGL5.Add(tuGL5);
                                                tupGLLstGLNormoul = tupGLLstGLNormoul.OrderBy(o => o.Item1).ToList();
                                            }
                                            if (i< pageNum-1)
                                                P1.DrawingSteelTrussBeamByGL(db, bridgeId, catalogid, i + 1, pageNum + tableNum, out dtProjectConfig, bridgeW, bridgeSlope, divCap, divHeight, tupGLLstGLNormoul);
                                            else
                                                P1.DrawingSteelTrussBeamByGLExtend(db, bridgeId, catalogid, i + 1, pageNum + tableNum, out dtProjectConfig, bridgeW, bridgeSlope, divCap, divHeight, tupGLLstGL5, divCapLast);
                                        }
                                        else
                                            P1.DrawingSteelTrussBeamByGL(db, bridgeId, catalogid, i + 1, pageNum + tableNum, out dtProjectConfig, bridgeW, bridgeSlope, divCap, divHeight, tupGLLst);
                                        drawingConfigModel = PictureFrameTools.GetDrawingConfig(dtProject, catalogid, dtProjectConfig);
                                        //LayoutManager LM = LayoutManager.Current;
                                        //LM.CurrentLayout = "图纸";
                                        if (db != null)
                                        {
                                            creatFolder(appPath + "\\SteelTrussBeamStructure");
                                            //file = appPath + "\\AviationBridgeGA\\桥型图.dwg";
                                            file = appPath + "\\SteelTrussBeamStructure\\" + drawingConfigModel.drawing_no + " " + drawingConfigModel.name + (i + 1) + ".dwg";
                                            db.SaveAs(file, DwgVersion.vAC18);

                                        }
                                        //start = start + 2 ;
                                    }
                                }
                            }
                            else
                            {
                                using (Services svc = new Services())
                                {
                                    SystemObjects.DynamicLinker.LoadApp("GripPoints", false, false);
                                    SystemObjects.DynamicLinker.LoadApp("PlotSettingsValidator", false, false);

                                    HostApplicationServices.Current = new HostAppServ(svc);
                                    Environment.SetEnvironmentVariable("DDPLOTSTYLEPATHS", ((HostAppServ)HostApplicationServices.Current).FindConfigPath(String.Format("PrinterStyleSheetDir")));
                                    using (Database db = new Database())
                                    {
                                        HostApplicationServices.WorkingDatabase = db;

                                        //db = new Database();
                                        InitConfig.InitStandardConfig(db, bridgeId);
                                        P1.DrawingSteelTrussBeamGLTable(db, bridgeId, catalogid, i + 1, pageNum + tableNum, out dtProjectConfig, bridgeW, bridgeSlope, divCap, divHeight, dicGL,ref dtQuatity, i - pageNum,divCapLast);
                                        drawingConfigModel = PictureFrameTools.GetDrawingConfig(dtProject, catalogid, dtProjectConfig);

                                        if (db != null)
                                        {
                                            creatFolder(appPath + "\\SteelTrussBeamStructure");
                                            //file = appPath + "\\AviationBridgeGA\\桥型图.dwg";
                                            file = appPath + "\\SteelTrussBeamStructure\\" + drawingConfigModel.drawing_no + " " + drawingConfigModel.name + (i + 1) + ".dwg";
                                            db.SaveAs(file, DwgVersion.vAC18);

                                        }

                                    }
                                }
                            }

                            using (Services ser = new Services())
                            {
                                SystemObjects.DynamicLinker.LoadApp("GripPoints", false, false);
                                SystemObjects.DynamicLinker.LoadApp("PlotSettingsValidator", false, false);

                                HostApplicationServices.Current = new HostAppServ(ser);
                                Environment.SetEnvironmentVariable("DDPLOTSTYLEPATHS", ((HostAppServ)HostApplicationServices.Current).FindConfigPath(String.Format("PrinterStyleSheetDir")));
                                //打开数据库(dwg⽂件)
                                using (Database database = new Database(false, false))//不加参数会出错
                                {

                                    database.ReadDwgFile(file, FileOpenMode.OpenForReadAndAllShare, false, "");
                                    LayoutTools.PlotDrawingByTK(database, "图纸", "ISO_full_bleed_A3_(420.00_x_297.00_MM)", "monochrome.ctb", "DWG To PDF.pc3", file, out filePath, ref fileList);
                                }
                            }

                        }
                        #endregion
                    }
                    else
                    {
                        #region 桥面宽度小于4.5m
                      

                        int pageNum = tupAddGLLst.Count;                       
                        int tableNum = tupAddGLLst.Count / 6;
                        int beamS = 1;
                        if (tupAddGLLst.Count - tableNum * 6 > 0)
                            tableNum = tableNum + 1;
                        for (int i = 0; i < pageNum + beamS + tableNum; i++)
                        {
                            if (i < pageNum)
                            {
                                using (Services svc = new Services())
                                {
                                    SystemObjects.DynamicLinker.LoadApp("GripPoints", false, false);
                                    SystemObjects.DynamicLinker.LoadApp("PlotSettingsValidator", false, false);

                                    HostApplicationServices.Current = new HostAppServ(svc);
                                    Environment.SetEnvironmentVariable("DDPLOTSTYLEPATHS", ((HostAppServ)HostApplicationServices.Current).FindConfigPath(String.Format("PrinterStyleSheetDir")));
                                    using (Database db = new Database())
                                    {
                                        HostApplicationServices.WorkingDatabase = db;

                                        //db = new Database();
                                        InitConfig.InitStandardConfig(db, bridgeId);
                                        //if (i < start + 2)
                                        //    P1.DrawingSteelTrussBeamByGL(db, bridgeId, catalogid, i + 1, tupGLLst.Count, out dtProjectConfig, bridgeW, bridgeSlope, divCap, divHeight, tupGLLst[i].Item2, tupGLLst[i].Item1, tupGLLst[i].Item4);
                                        //else

                                        P1.DrawingSteelTrussBeamByAverageGL(db, bridgeId, catalogid, i + 1, pageNum + tableNum+ 8, out dtProjectConfig, bridgeW, bridgeSlope, divCap, divHeight, tupAddGLLst,tupleGLLst,light_width,light_left_length,light_right_length);
                                        drawingConfigModel = PictureFrameTools.GetDrawingConfig(dtProject, catalogid, dtProjectConfig);
                                        //LayoutManager LM = LayoutManager.Current;
                                        //LM.CurrentLayout = "图纸";
                                        if (db != null)
                                        {
                                            creatFolder(appPath + "\\SteelTrussBeamStructure");
                                            //file = appPath + "\\AviationBridgeGA\\桥型图.dwg";
                                            file = appPath + "\\SteelTrussBeamStructure\\" + drawingConfigModel.drawing_no + " " + drawingConfigModel.name + (i + 1) + ".dwg";
                                            db.SaveAs(file, DwgVersion.vAC18);

                                        }
                                        //start = start + 2 ;
                                    }
                                }
                            }
                            else if (i < pageNum+ beamS)
                            {
                                using (Services svc = new Services())
                                {
                                    SystemObjects.DynamicLinker.LoadApp("GripPoints", false, false);
                                    SystemObjects.DynamicLinker.LoadApp("PlotSettingsValidator", false, false);

                                    HostApplicationServices.Current = new HostAppServ(svc);
                                    Environment.SetEnvironmentVariable("DDPLOTSTYLEPATHS", ((HostAppServ)HostApplicationServices.Current).FindConfigPath(String.Format("PrinterStyleSheetDir")));
                                    using (Database db = new Database())
                                    {
                                        HostApplicationServices.WorkingDatabase = db;

                                        //db = new Database();
                                        InitConfig.InitStandardConfig(db, bridgeId);
                                        //if (i < start + 2)
                                        //    P1.DrawingSteelTrussBeamByGL(db, bridgeId, catalogid, i + 1, tupGLLst.Count, out dtProjectConfig, bridgeW, bridgeSlope, divCap, divHeight, tupGLLst[i].Item2, tupGLLst[i].Item1, tupGLLst[i].Item4);
                                        //else

                                        P1.DrawingSteelTrussBeamAverageGLNote(db, bridgeId, catalogid, i +1, pageNum + tableNum + 8, out dtProjectConfig, i- pageNum+1);
                                        drawingConfigModel = PictureFrameTools.GetDrawingConfig(dtProject, catalogid, dtProjectConfig);
                                        //LayoutManager LM = LayoutManager.Current;
                                        //LM.CurrentLayout = "图纸";
                                        if (db != null)
                                        {
                                            creatFolder(appPath + "\\SteelTrussBeamStructure");
                                            //file = appPath + "\\AviationBridgeGA\\桥型图.dwg";
                                            file = appPath + "\\SteelTrussBeamStructure\\" + drawingConfigModel.drawing_no + " " + drawingConfigModel.name + (i + 1) + ".dwg";
                                            db.SaveAs(file, DwgVersion.vAC18);

                                        }
                                        //start = start + 2 ;
                                    }
                                }
                            }
                            else
                            {
                                using (Services svc = new Services())
                                {
                                    SystemObjects.DynamicLinker.LoadApp("GripPoints", false, false);
                                    SystemObjects.DynamicLinker.LoadApp("PlotSettingsValidator", false, false);

                                    HostApplicationServices.Current = new HostAppServ(svc);
                                    Environment.SetEnvironmentVariable("DDPLOTSTYLEPATHS", ((HostAppServ)HostApplicationServices.Current).FindConfigPath(String.Format("PrinterStyleSheetDir")));
                                    using (Database db = new Database())
                                    {
                                        HostApplicationServices.WorkingDatabase = db;

                                        //db = new Database();
                                        InitConfig.InitStandardConfig(db, bridgeId);
                                        P1.DrawingSteelTrussBeamAverageGLTable(db, bridgeId, catalogid, i + 8, pageNum + tableNum+ 8, out dtProjectConfig, bridgeW, bridgeSlope, divCap, divHeight, dicAddGL, tupleGLLst, ref dtQuatity, i - pageNum- beamS, light_width, light_length);
                                        drawingConfigModel = PictureFrameTools.GetDrawingConfig(dtProject, catalogid, dtProjectConfig);

                                        if (db != null)
                                        {
                                            creatFolder(appPath + "\\SteelTrussBeamStructure");
                                            //file = appPath + "\\AviationBridgeGA\\桥型图.dwg";
                                            file = appPath + "\\SteelTrussBeamStructure\\" + drawingConfigModel.drawing_no + " " + drawingConfigModel.name + (i + 1) + ".dwg";
                                            db.SaveAs(file, DwgVersion.vAC18);

                                        }

                                    }
                                }
                            }

                            using (Services ser = new Services())
                            {
                                SystemObjects.DynamicLinker.LoadApp("GripPoints", false, false);
                                SystemObjects.DynamicLinker.LoadApp("PlotSettingsValidator", false, false);

                                HostApplicationServices.Current = new HostAppServ(ser);
                                Environment.SetEnvironmentVariable("DDPLOTSTYLEPATHS", ((HostAppServ)HostApplicationServices.Current).FindConfigPath(String.Format("PrinterStyleSheetDir")));
                                //打开数据库(dwg⽂件)
                                using (Database database = new Database(false, false))//不加参数会出错
                                {

                                    database.ReadDwgFile(file, FileOpenMode.OpenForReadAndAllShare, false, "");
                                    LayoutTools.PlotDrawingByTK(database, "图纸", "ISO_full_bleed_A3_(420.00_x_297.00_MM)", "monochrome.ctb", "DWG To PDF.pc3", file, out filePath, ref fileList);
                                }
                            }

                        }
                        #endregion
                    }
                    #region 合并pdf   
                    FileInfo filepath = new FileInfo(file);
                    string dir = filepath.DirectoryName + "\\PDF\\";
                    string fileName = drawingConfigModel.drawing_no + " " + drawingConfigModel.name;
                    filePath = dir + fileName + ".pdf";
                    ITextPdfHelper.mergePDFFiles(fileList, filePath);
                    #endregion

                    if (!File.Exists(filePath))
                        filePath = file.Replace(".dwg", "") + ".dwg";
                }
            }
            return filePath;
        }


        public static void creatFolder(String path)
        {
            //不存在 则创建
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }
    }
}
